package com.nas.app.task.command;

import java.security.ProviderException;

import com.nas.app.task.Task;

public class Interpreter {
    
    public static Command getCommand(Task task) throws ClassNotFoundException {
        String className = "com.nas.app.task.command." + task.getTaskName()+"Command";
        Class<?> commandClass = Class.forName(className);
        Command command = null;
        try {
            command = (Command) commandClass.newInstance();
            command.setTask(task);
        } catch (InstantiationException e) {
           throw new ProviderException(e);
        } catch (IllegalAccessException e) {
            throw new ProviderException(e);
        }
        return command;
    }
    
    public static boolean isExists(Task task) {
        String className = "com.nas.app.task.command." + task.getTaskName()+"Command";
        boolean exists = true;
        try {
            Class.forName(className);            
        } catch (ClassNotFoundException e) {
            exists = false;
        }
        return exists;
    }

}
